<?php
###
#  Baing PHP 框架 1.0.0
#  http://baing.co/
#
#  Copyright: 白晓阳
#  License: CC BY-NC-SA 4.0
#  https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh
###

namespace bai\feature;


trait Contexts
{
    final public static function filter(array $context, string $className, bool $single = true): array
    {
        $full = str_contains($className, '\\');
        $list = array_filter($context, function ($item) use ($className, $full) {
            return $full && $item['action'] === $className || str_ends_with($item['action'], "\\$className");
        });
        if ($single) return end($list);
        return $list;
    }
}